//import global from './global'
cc.Class({
    extends: cc.Component,

    properties: {
        head:cc.Sprite,

        bgCreatRoom:cc.Node,

        bgJoinRoom:cc.Node,

        roomNumLab:[cc.Label],

        roomBtn:cc.Node,
    },


    onLoad () {
        var murl = 'http://img5.imgtn.bdimg.com/it/u=386319321,13242164&fm=27&gp=0.jpg';

        cc.loader.load(murl,function (err, texture) {
            //cc.log(texture);
            // var frame=new cc.SpriteFrame(texture);
            // self.getComponent(cc.Sprite).spriteFrame=frame;
            // self.node.x = cc.winSize.width/2;
            // self.node.y = cc.winSize.height/2;
            this.head.spriteFrame = new cc.SpriteFrame(texture);
            this.head.node.width = 150;
            this.head.node.height = 150;
       }.bind(this));

       //已经输入的数字个数
       this.hasInput = 0;
    },

    //输入房间号
    inputRoomNumBtn:function(event,eventCustomData){
        
        if(Number(eventCustomData) <= 9 && Number(eventCustomData) >= 0){
            if(this.hasInput === 6){
                return;
            }
            if(this.hasInput > 0){
                for(var i = this.hasInput;i > 0;i--){
                    this.roomNumLab[i].string = this.roomNumLab[i - 1].string;
                    this.roomNumLab[i].node.opacity = 255;
                }
            }
            this.roomNumLab[0].string = eventCustomData;
            this.roomNumLab[0].node.opacity = 255;
            

            this.hasInput++;
        }else if(Number(eventCustomData) === 10){
            if(this.hasInput === 0){
                return;
            }
            for(var i = 0;i < this.hasInput - 1;i++){
                this.roomNumLab[i].string = this.roomNumLab[i + 1].string;
            }
            this.roomNumLab[i].string = 0;
            this.roomNumLab[i].node.opacity = 0;
            this.hasInput--;
        }else if(Number(eventCustomData) === 11){
            for(var i = 0;i < this.hasInput;i++){
                this.roomNumLab[i].string = 0;
                this.roomNumLab[i].node.opacity = 0;
            }
            this.hasInput = 0;
        }
    },

    //创建房间按钮
    btnCreatRoom:function(){
        this.bgCreatRoom.active = true;
        //this.roomBtn.active = false;
    },

    //加入房间按钮
    btnJoinRoom:function(event,eventCustomData){
        this.bgJoinRoom.active = true;
        //this.roomBtn.active = false;
        
    },

    //关闭页面
    closeCurrent:function(event,eventCustomData){
        if(eventCustomData === '1'){
            this.bgCreatRoom.active = false;
        }else{
            this.bgJoinRoom.active = false;
        }
    },

    start () {

    },

    // update (dt) {},
});
